<template>
	<div class="zh-operation-manual">
		<nav-header></nav-header>
		<div class="zh-table"
			v-loading="loading.status"
		    :element-loading-text="loading.txt"
		>
			<div class="zh-table-open clear">
				<div class="zh-open-left fl">
                    <el-button @click="isSort = false" plain style="min-width: 80px;padding: 8px 15px;margin-right: 8px" v-if="isSort">排序</el-button>
                    <el-button @click="orderChange" plain style="min-width: 80px;padding: 8px 15px;margin-right: 8px" v-else>完成</el-button>
					<div class="open-width">
						<el-input v-model="keyword" placeholder="请输入标题搜索" @keyup.enter.native="searchFunc"></el-input>
					</div>
					<el-button type="primary" @click="searchFunc">搜索</el-button>
					<el-button type="primary" @click="reset">重置</el-button>
				</div>
				<div class="zh-open-right fr">
					<el-button type="primary" @click="addManual()">添加手册</el-button>
					<el-button type="danger" @click="deleteMuiltFeedback_confirm">批量删除</el-button>
				</div>
			</div>
			<div class="zh-table-contents"> 
				<el-table
				    :data="feedBackData"
				    @selection-change="tableSelectionChange"
				    border
				    max-height="600"
				    style="width: 100%">
				    <el-table-column
				      type="selection"
				      width="50"
				      align="center"
				      fixed>
				    </el-table-column>
				    <el-table-column
				      prop="order_num"
				      label="序号"
				      align="center"
				      width="70"
				      show-overflow-tooltip>
				      <template slot-scope="scope">
					      <el-input v-model="scope.row.order_num" ></el-input>
					  </template>
                       <template slot-scope="scope">
                            <el-input v-model="scope.row.order_num" :disabled="isSort"></el-input>
                        </template>
				    </el-table-column>
				    <el-table-column
				      prop="title"
				      label="标题"
				      align="center"
				      show-overflow-tooltip
				      >
				    </el-table-column>
				    <!-- <el-table-column
				      prop="clicks"
				      label="点击量"
				      align="center"
				      show-overflow-tooltip
				      >
				    </el-table-column> -->
				    <el-table-column
				      prop="create_name"
				      label="发布人"
				      align="center"
				      show-overflow-tooltip
				      >
				    </el-table-column>
				    <el-table-column
				      prop="create_time"
				      label="更新时间"
				      align="center"
				      show-overflow-tooltip
				      >
				    </el-table-column>
				    <el-table-column
				      label="操作"
				      align="center"
				      width="120"
				      >
				      	<template slot-scope="scope">
			      	       <el-button @click="changeFeedback_confirm(scope.row,2)" v-if="parseInt(scope.row.status) === 1" type="text" >隐藏</el-button>
						   <el-button @click="changeFeedback_confirm(scope.row,1)" v-if="parseInt(scope.row.status) === 2" type="text" >显示</el-button>
			      	       <el-button  @click="deleteFeedback_confirm(scope.row)" type="text" class="delete-button">删除</el-button>
			      	    </template>
				    </el-table-column>
				</el-table>
				<div class="table-pagination" v-show="total_number > 10">
					<el-pagination
					    @size-change="handleSizeChange"
					    @current-change="handleCurrentChange"
					    :current-page="feedBackParam.page_index"
					    :page-sizes="[10, 20, 30, 40, 50, 100]"
					    :page-size="feedBackParam.page_size"
					    layout="total, sizes, prev, pager, next, jumper"
					    :total="total_number">
					</el-pagination>
					<div class="pagination-button">
						<el-button 
							@click="getList"
							type="primary" icon="el-icon-refresh" 
							circle title="刷新数据" size="mini" >
						</el-button>
					</div>
				</div>
			</div>
		</div>
	</div>
</template>
<script>
  	export default {
	    data() {
		    return {
		    	loading:{
					status:false,
					txt:'获取数据...',
				},
		    	feedBackParam:{
		       		keyword: '',
		       		page_index:1,
		       		page_size:10,
                },
                isSort: true, // 排序
				keyword: '',
		        selected:[],
		        feedBackData:[],
		        status_arr:{1:'正常',2:'隐藏'},
				total_number: 0,//共几条
				rowLen: 0,
		    }
		},
		created(){
			this.getList();
	    },
		methods: {
			searchFunc(){
				this.feedBackParam.page_index = 1;
				this.feedBackParam.keyword = this.keyword;
				this.getList();
			},
			reset() {
				this.feedBackParam.page_index = 1;
				this.feedBackParam.page_size = 10;
				this.feedBackParam.keyword = '';
				this.keyword = '';
				this.getList();
			},
			orderChange(){
				let success = ( data => {
                    this.loading.status = false;
                    this.isSort = true;
		    		this.$message.success( data.msg) ;
		    		this.getList();
					
				});
				var params = {
					id:getOneColumn( this.feedBackData , 'id' ),
					order_num: getOneColumn( this.feedBackData , 'order_num')
				}
				this.$ajax.post('api/setting/manual_order',params,{func:{success:success}})
			},
			//添加手册
			addManual(){
				this.$router.push("/portal/help/add-manual")
			},
			//选中
		    tableSelectionChange(val) {
                this.selected = val;
            },
			handleSizeChange(val) {
				 this.feedBackParam.page_index = 1;
		    	this.feedBackParam.page_size = val;
		    	this.getList();
		    },
		    handleCurrentChange(val) {
		        this.feedBackParam.page_index = val;
		        this.getList();
		    },
		    getList(){
		    	this.loading.status = true;
		    	// 重写成功回调
				let success = ( data => {
					this.loading.status = false;
					this.feedBackData = data.data.data;
					this.total_number = data.data.data_sum;
				});
				let fail = ( data => {
					this.loading.status = false;
					this.$message.error(data.msg)
				})
  				this.$ajax.get('api/setting/operation_manual_data',{params:this.feedBackParam,func:{success:success,fail:fail}})
		    	
		    },
		    changeFeedback_confirm(obj,status){
				let yes = ( data => {
					this.changeFeedback(obj.id,status);
				})
				let cancel = ( data => {})
				this.e_confirm({yes:yes,cancel:cancel,txt:'确定将 '+obj.title+' 标记为 '+this.status_arr[parseInt(status)]+' 吗？'});

			},
		    changeFeedback(id,status){
		    	let success = ( data => {
					this.$message.success(data.msg);

					if (this.feedBackData.length - this.rowLen === 0) {
						if (this.feedBackParam.page_index > 1) {
							this.feedBackParam.page_index--;
						} else {
							this.feedBackParam.page_index = 1;
						}
					}

					this.getList();
				});
		    	this.$ajax.put('api/setting/change_operation_manual',{id:id,status:status},{func:{success:success}})
		    },
		    deleteFeedback_confirm(obj){
				let yes = ( data => {
					this.rowLen = 1;
					this.changeFeedback(obj.id,0);
				})
				let cancel = ( data => {})
				this.e_confirm({yes:yes,cancel:cancel,txt:'确定将 '+obj.title+' 删除吗？'});

			},
			deleteMuiltFeedback_confirm(){
				if( this.selected.length === 0 ) {
					this.$message.warning("请选择要删除的项");
					return false;
				}
				let yes = ( data => {
					this.rowLen = this.selected.length;
					this.muilDeleteFeedback();
				})
				let cancel = ( data => {})
				this.e_confirm({yes:yes,cancel:cancel,txt:'确定要删除选中的项吗？'});

			},
			muilDeleteFeedback(){
				var ids = [];
				for (var i = this.selected.length - 1; i >= 0; i--) {
					ids.push(this.selected[i].id)
				}
				this.changeFeedback(ids,0);
			}
		    
		},
  	}
</script>
<style lang="scss">
	.zh-operation-manual {
		.el-table__body-wrapper table tbody {
			td:nth-child(7) {
				padding: 0;
			}
		}
	}
</style>